load("@fbcode_macros//build_defs/lib:rust_oss.bzl", "rust_oss")
load("@fbsource//tools/build_defs:rust_library.bzl", "rust_library")
load("@fbsource//tools/build_defs:rust_unittest.bzl", "rust_unittest")

oncall("scm_server_infra")

rust_library(
    name = "bookmarks",
    srcs = glob(["src/**/*.rs"]),
    test_deps = [
        "fbsource//third-party/rust:ascii",
        "fbsource//third-party/rust:maplit",
        "fbsource//third-party/rust:quickcheck",
        "fbsource//third-party/rust:tokio",
        "//common/rust/shed/ascii_ext:ascii_ext",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/sql:sql",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/mononoke_types:mononoke_types-mocks",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:derive_more",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:thiserror",
        ":bookmarks_types",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/justknobs_stub:justknobs",
        "//common/rust/shed/shared_error:shared_error",
        "//common/rust/shed/sql:sql",
        "//common/rust/shed/stats:stats",
        "//eden/mononoke/common/rust/sql_ext:sql_ext",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/server/context:context",
    ],
)

rust_library(
    name = "dbbookmarks",
    srcs = glob([
        "dbbookmarks/src/**/*.rs",
        "dbbookmarks/schemas/**/*.sql",
    ]),
    autocargo = {"cargo_toml_dir": "dbbookmarks"},
    test_deps = [
        "fbsource//third-party/rust:ascii",
        "fbsource//third-party/rust:maplit",
        "fbsource//third-party/rust:quickcheck",
        "fbsource//third-party/rust:tokio",
        "//common/rust/shed/ascii_ext:ascii_ext",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/mononoke_types:mononoke_types-mocks",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:rand",
        "fbsource//third-party/rust:tracing",
        ":bookmarks",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/justknobs_stub:justknobs",
        "//common/rust/shed/stats:stats",
        "//eden/mononoke/common/futures_watchdog:futures_watchdog",
        "//eden/mononoke/common/rust/sql_ext:sql_ext",
        "//eden/mononoke/common/sql_construct:sql_construct",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/server/context:context",
    ],
)

rust_unittest(
    name = "dbbookmarks-test",
    srcs = glob(["dbbookmarks/tests/**/*.rs"]),
    autocargo = {"cargo_toml_dir": "dbbookmarks"},
    crate = "dbbookmarks_test",
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:maplit",
        "fbsource//third-party/rust:quickcheck",
        "fbsource//third-party/rust:tokio",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//common/rust/shed/quickcheck_arbitrary_derive:quickcheck_arbitrary_derive",
        "//common/rust/shed/sql:sql",
        "//eden/mononoke/bookmarks:bookmarks",
        "//eden/mononoke/bookmarks:dbbookmarks",
        "//eden/mononoke/common/sql_construct:sql_construct",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/mononoke_types:mononoke_types-mocks",
        "//eden/mononoke/server/context:context",
    ],
)

rust_library(
    name = "bookmarks_cache",
    srcs = glob(["bookmarks_cache/*.rs"]),
    autocargo = {"cargo_toml_dir": "bookmarks_cache"},
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:enum-map",
        ":bookmarks_types",
        "//common/rust/shed/facet:facet",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/server/context:context",
    ],
)

rust_library(
    name = "warm_bookmarks_cache",
    srcs = glob(["warm_bookmarks_cache/*.rs"]),
    autocargo = {"cargo_toml_dir": "warm_bookmarks_cache"},
    named_deps = {
        "slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat",
    } | ({} if rust_oss.is_oss_build() else {
        "MononokeWarmBookmarkCacheStats_ods3_types": "//eden/mononoke/facebook/ods3_schemas:MononokeWarmBookmarkCacheStats_ods3-rust",
    }),
    test_deps = [
        "fbsource//third-party/rust:maplit",
        "fbsource//third-party/rust:rand_distr",
        "fbsource//third-party/rust:tokio",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//eden/mononoke/blobstore:delayblob",
        "//eden/mononoke/blobstore:memblob",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/common/rust/sql_ext:sql_ext",
        "//eden/mononoke/filestore:filestore",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/repo_attributes/commit_graph/commit_graph:commit_graph",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_event_publisher:repo_event_publisher",
        "//eden/mononoke/repo_factory:test_repo_factory",
        "//eden/mononoke/tests/fixtures:fixtures",
        "//eden/mononoke/tests/utils:tests_utils",
    ],
    deps = ([
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:enum-map",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:itertools",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        ":bookmarks",
        ":bookmarks_cache",
        ":bookmarks_types",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/futures_stats:futures_stats",
        "//common/rust/shed/justknobs_stub:justknobs",
        "//common/rust/shed/lock_ext:lock_ext",
        "//common/rust/shed/stats:stats",
        "//eden/mononoke/common/futures_watchdog:futures_watchdog",
        "//eden/mononoke/derived_data:basename_suffix_skeleton_manifest_v3",
        "//eden/mononoke/derived_data:blame",
        "//eden/mononoke/derived_data:case_conflict_skeleton_manifest",
        "//eden/mononoke/derived_data:changeset_info",
        "//eden/mononoke/derived_data:deleted_manifest",
        "//eden/mononoke/derived_data:derived_data_manager",
        "//eden/mononoke/derived_data:fastlog",
        "//eden/mononoke/derived_data:fsnodes",
        "//eden/mononoke/derived_data:skeleton_manifest",
        "//eden/mononoke/derived_data:skeleton_manifest_v2",
        "//eden/mononoke/derived_data:unodes",
        "//eden/mononoke/derived_data:inferred_copy_from",
        "//eden/mononoke/derived_data/content_manifest_derivation:content_manifest_derivation",
        "//eden/mononoke/derived_data/filenodes_derivation:filenodes_derivation",
        "//eden/mononoke/derived_data/mercurial_derivation:mercurial_derivation",
        "//eden/mononoke/git/git_types:git_types",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/phases:phases",
        "//eden/mononoke/repo_attributes/repo_derived_data:repo_derived_data",
        "//eden/mononoke/repo_attributes/repo_event_publisher:repo_event_publisher",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/server/context:context",
    ] + ([] if rust_oss.is_oss_build() else [
        "fbsource//third-party/rust:lazy_static",
        "//eden/mononoke/facebook/ods3_schemas:MononokeWarmBookmarkCacheStats_ods3-rs_bindings",
    ])),
)

rust_library(
    name = "bookmarks_types",
    srcs = glob(["bookmarks_types/**/*.rs"]),
    autocargo = {"cargo_toml_dir": "bookmarks_types"},
    test_deps = ["//eden/mononoke/mononoke_macros:mononoke_macros"],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:ascii",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:quickcheck",
        "//common/rust/shed/ascii_ext:ascii_ext",
        "//common/rust/shed/quickcheck_arbitrary_derive:quickcheck_arbitrary_derive",
        "//common/rust/shed/sql:sql",
        "//eden/scm/lib/edenapi/types:edenapi_types",
    ],
)

rust_library(
    name = "bookmarks_movement",
    srcs = glob(["bookmarks_movement/**/*.rs"]),
    autocargo = {"cargo_toml_dir": "bookmarks_movement"},
    test_deps = [
        "fbsource//third-party/rust:maplit",
        "//common/rust/shed/borrowed:borrowed",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//eden/mononoke/filestore:filestore",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/mononoke_types:mononoke_types-mocks",
        "//eden/mononoke/repo_factory:test_repo_factory",
        "//eden/mononoke/tests/utils:tests_utils",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:bytes",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:itertools",
        "fbsource//third-party/rust:thiserror",
        ":bookmarks",
        ":bookmarks_types",
        "//common/rust/shed/borrowed:borrowed",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/futures_ext:futures_ext",
        "//common/rust/shed/futures_stats:futures_stats",
        "//common/rust/shed/justknobs_stub:justknobs",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/bonsai_git_mapping:bonsai_git_mapping",
        "//eden/mononoke/bonsai_globalrev_mapping:bonsai_globalrev_mapping",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/common/rust/sql_ext:sql_ext",
        "//eden/mononoke/derived_data:case_conflict_skeleton_manifest",
        "//eden/mononoke/derived_data:skeleton_manifest",
        "//eden/mononoke/features/cross_repo_sync:cross_repo_sync",
        "//eden/mononoke/features/repo_update_logger:repo_update_logger",
        "//eden/mononoke/git_source_of_truth:git_source_of_truth",
        "//eden/mononoke/hooks:hooks",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/permission_checker:permission_checker",
        "//eden/mononoke/phases:phases",
        "//eden/mononoke/pushrebase:pushrebase",
        "//eden/mononoke/pushrebase:pushrebase_hook",
        "//eden/mononoke/pushrebase:pushrebase_hooks",
        "//eden/mononoke/pushrebase_mutation_mapping:pushrebase_mutation_mapping",
        "//eden/mononoke/repo_attributes/commit_graph/commit_graph:commit_graph",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_bookmark_attrs:repo_bookmark_attrs",
        "//eden/mononoke/repo_attributes/repo_cross_repo:repo_cross_repo",
        "//eden/mononoke/repo_attributes/repo_derived_data:repo_derived_data",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/repo_attributes/repo_lock:repo_lock",
        "//eden/mononoke/repo_attributes/repo_permission_checker:repo_permission_checker",
        "//eden/mononoke/repo_authorization:repo_authorization",
        "//eden/mononoke/server/context:context",
    ],
)
